package com.tetra.arena.core;

import java.sql.ResultSet;
import java.sql.SQLException;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

import com.tetra.arena.handlers.NotificationHandler;

public class NotificationSender implements NotificationHandler {

	ArenaSystems asys;

	public NotificationSender(ArenaSystems instance) {
		this.asys = instance;
	}

	public void sendPlayerUpdate(String Msg, ResultSet members, ChatColor color) {
		if (members != null) {
			try {
				while (members.next()) {
					if (members.getString("username") != null) {
						Player target = asys.getServer().getPlayer(
								members.getString("username"));
						if (target.isOnline()) {
							target.sendMessage(color + Msg);
						}
					}
				}
			} catch (Exception ex) {
				System.out.println(ex.getMessage());
			} finally{
				try {
					if(members.getStatement() != null){
						try{
							members.getStatement().close();
						} catch (SQLException ex){
							
						}
					}
				} catch (SQLException e) {
				}
				if (members != null) {
					try {
						members.close();
					} catch (SQLException ex) {
					}
				}
			}

		}
	}
}